// ScoreManager.ts
import { _decorator, Component, EventTarget } from 'cc';
import { GameEvent } from './EventType';

const { ccclass, property } = _decorator;

@ccclass('ScoreManager')
export class ScoreManager extends Component {
    private currentScore: number = 0;
    private eventTarget: EventTarget = new EventTarget();

    /** 增加分数 */
    public addScore(points: number) {
        this.currentScore += points;
        this.eventTarget.emit(GameEvent.SCORE_CHANGE, this.currentScore);
    }

    /** 重置分数 */
    public resetScore() {
        this.currentScore = 0;
        this.eventTarget.emit(GameEvent.SCORE_CHANGE, this.currentScore);
    }

    /** 获取当前分数 */
    public getScore(): number {
        return this.currentScore;
    }

    /** 获取事件目标 */
    public getEventTarget(): EventTarget {
        return this.eventTarget;
    }

    onDestroy() {
        this.eventTarget.targetOff(this);
    }
}
